package com.jjkj.environmental.environmental.presenter.base

import com.jjkj.environmental.environmental.di.DaggerPresenterComponent
import com.jjkj.environmental.environmental.di.PresenterComponent
import com.jjkj.environmental.environmental.view.base.BaseView
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import javax.inject.Inject

abstract class BasePresenter<V : BaseView<*>> {
    private var view: V? = null
    @Inject
    lateinit var compositeDisposable: CompositeDisposable

    init {
        this.initInject()
    }

    protected fun getMvpView(): V {
        return this.view!!
    }

    fun bindView(view: V) {
        this.view = view
    }

    fun unbindView() {
        this.view = null
        compositeDisposable.clear()
    }

    protected fun bindRxLife(disposable: Disposable) {
        compositeDisposable.add(disposable)
    }

    protected fun getComponent(): PresenterComponent {
        return DaggerPresenterComponent.create()
    }

    abstract fun initInject()

}